<?php

class AuthRuleModel extends Model{

    /**
     * [getMenu 获取导航菜单]
     * @param  [type] $pid [description]
     * @return [type]      [description]
     */
    public function getMenu($pid){
        $tree = new Category('AuthRule',array('id','pid','title','cname'));
        if( in_array(ADMIN_ID,explode(',', Yaf\Registry::get("config")->application->superids) ) ){
            $menulist = $tree->getList('ismenu=1','0','sort asc,id asc');
        }else{
            $rule = $this->table('__AUTH_GROUP_ACCESS__ as a')
                        ->field('b.rules')
                        ->join(' left join __AUTH_GROUP__ as b on a.group_id=b.id')
                        ->where('a.uid='.ADMIN_ID)
                        ->select();
            foreach ($rule as $key => $value) {
                $ruleids[] = $value['rules'];
            }
            $menulist = $tree->getList('ismenu=1 and id in ('.implode(',',$ruleids).')','0','sort asc,id asc');
        }
        $tree->getTree($menulist,0);
        $menu = $tree->getArr($pid);
        //获取当前id的ids;
        // $rule_id = $this->where(array('name'=>strtolower(MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME)))->getField('id');
        // $menuids = $tree->getPath($rule_id);
        // foreach ($menuids as $key => $value) {
        //     $menu_ids[] = $value['id']; 
        // }
        return array(
            'menulist' =>$menu,
            'menuids' => array(),
        );
    }
}